package com.woniu.elderly.serve.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.common.dto.ServeAuditDTO;
import com.woniu.common.entity.Result;
import com.woniu.common.entity.ServeAudit;
import com.woniu.elderly.serve.service.ServeAuditService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/serveaudit")
public class ServeAuditController {
    @Autowired
    private ServeAuditService serveAuditService;

    //查询全部审核
    @PostMapping("/{pageIndex}/{pageSize}")
    public Result<Page<ServeAudit>> findAll(@PathVariable("pageIndex") int pageIndex,
                                @PathVariable("pageSize") int pageSize,
                                @RequestBody ServeAuditDTO serveAuditDTO){
        log.info("serveaudit-findAll:pageIndex={},pageSize={},serveAuditDTO={}", pageIndex, pageSize, serveAuditDTO);
        return Result.ok(serveAuditService.findAll(pageIndex, pageSize, serveAuditDTO));
    }

    //根据id查询审核
    @GetMapping("/{id}")
    public Result<ServeAudit> findById(@PathVariable("id") int id){
        log.info("serveaudit-findById:id={}", id);
        return Result.ok(serveAuditService.findById(id));
    }

    //添加审核
    @PostMapping("/")
    public Result<Integer> add(@RequestBody ServeAudit serveAudit){
        log.info("serveaudit-add:serveAudit={}", serveAudit);
        return Result.ok(serveAuditService.add(serveAudit));
    }

    //删除审核
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable("id") int id){
        log.info("serveaudit-remove:id={}", id);
        serveAuditService.remove(id);
        return Result.ok("删除审核");
    }

    //修改审核
    @PutMapping("/")
    public Result<Void> modify(@RequestBody ServeAudit serveAudit){
        log.info("serveaudit-modify:serveAudit={}", serveAudit);
        serveAuditService.modify(serveAudit);
        return Result.ok("修改审核");
    }
}
